Trò chơi đua xe động vật trong UNITY Engine
114.910 lượt xem;
- SpriteTimelineKey.cs
- Spriter /
- Editor /
- Spriter2Unity /
- ThirdParty /
- Assets /
- project /
1 /*
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 using UnityEngine;
24 using System;
25 using System.Collections.Generic;
26 using System.Linq;
27 using System.Text;
28 using System.Xml;
29
30 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
31 {
32 public class SpriteTimelineKey : SpatialTimelineKey
33 {
34 new public const string XmlKey = "object";
35
36 public File File { get; private set; }
37 public Vector2 Pivot { get; private set; }
38 public Color Tint { get; private set; }
39
40 public Vector2 GetPivotOffetFromMiddle()
41 {
42 var mid = File.Size / 2;
43 var pvt = new Vector2(
44 File.Size.x * Pivot.x,
45 File.Size.y * Pivot.y);
46
47 var retVal = mid - pvt;
48 return retVal;
49 }
50
51 public SpriteTimelineKey(XmlElement element, Timeline timeline)
52 : base(element, timeline)
53 { }
54
55 protected override void Parse(XmlElement element, Timeline timeline)
56 {
57 base.Parse(element, timeline);
58
59 var objElement = element[XmlKey];
60
61 File = GetFile(objElement);
62
63 Spatial = new SpatialInfo(objElement);
64
65 Vector2 pivot;
66 pivot.x = objElement.GetFloat("pivot_x", File.Pivot.x);
67 pivot.y = objElement.GetFloat("pivot_y", File.Pivot.y);
68 Pivot = pivot;
69
70 Color tint = Color.white;
71 tint.r = objElement.GetFloat("r", 1.0f);
72 tint.g = objElement.GetFloat("g", 1.0f);
73 tint.b = objElement.GetFloat("b", 1.0f);
74 tint.a = objElement.GetFloat("a", 1.0f);
75 Tint = tint;
76 }
77
78 File GetFile(XmlElement element)
79 {
80 var folderId = element.GetInt("folder", -1);
81 var fileId = element.GetInt("file", -1);
82
83 File file = null;
84 var folder = Timeline.Animation.Entity.Scml.GetFolder(folderId);
85 if (folder != null)
86 {
87 file = folder.GetFile(fileId);
88 if (file == null)
89 {
90 Debug.LogError(string.Format("File Not Found! folder: {0} file: {1}", folderId, fileId));
91 }
92 }
93 else
94 {
95 Debug.LogError(string.Format("Folder Not Found! folder: {0}", folderId));
96 }
97 return file;
98 }
99 }
100 }
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 using UnityEngine;
24 using System;
25 using System.Collections.Generic;
26 using System.Linq;
27 using System.Text;
28 using System.Xml;
29
30 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
31 {
32 public class SpriteTimelineKey : SpatialTimelineKey
33 {
34 new public const string XmlKey = "object";
35
36 public File File { get; private set; }
37 public Vector2 Pivot { get; private set; }
38 public Color Tint { get; private set; }
39
40 public Vector2 GetPivotOffetFromMiddle()
41 {
42 var mid = File.Size / 2;
43 var pvt = new Vector2(
44 File.Size.x * Pivot.x,
45 File.Size.y * Pivot.y);
46
47 var retVal = mid - pvt;
48 return retVal;
49 }
50
51 public SpriteTimelineKey(XmlElement element, Timeline timeline)
52 : base(element, timeline)
53 { }
54
55 protected override void Parse(XmlElement element, Timeline timeline)
56 {
57 base.Parse(element, timeline);
58
59 var objElement = element[XmlKey];
60
61 File = GetFile(objElement);
62
63 Spatial = new SpatialInfo(objElement);
64
65 Vector2 pivot;
66 pivot.x = objElement.GetFloat("pivot_x", File.Pivot.x);
67 pivot.y = objElement.GetFloat("pivot_y", File.Pivot.y);
68 Pivot = pivot;
69
70 Color tint = Color.white;
71 tint.r = objElement.GetFloat("r", 1.0f);
72 tint.g = objElement.GetFloat("g", 1.0f);
73 tint.b = objElement.GetFloat("b", 1.0f);
74 tint.a = objElement.GetFloat("a", 1.0f);
75 Tint = tint;
76 }
77
78 File GetFile(XmlElement element)
79 {
80 var folderId = element.GetInt("folder", -1);
81 var fileId = element.GetInt("file", -1);
82
83 File file = null;
84 var folder = Timeline.Animation.Entity.Scml.GetFolder(folderId);
85 if (folder != null)
86 {
87 file = folder.GetFile(fileId);
88 if (file == null)
89 {
90 Debug.LogError(string.Format("File Not Found! folder: {0} file: {1}", folderId, fileId));
91 }
92 }
93 else
94 {
95 Debug.LogError(string.Format("Folder Not Found! folder: {0}", folderId));
96 }
97 return file;
98 }
99 }
100 }